import { mock, Random } from 'mockjs'
const domain = '/api/'


// 轮播图数据
const PICTURE = ['AiyWuByWklrrUDlFignR', 'TekJlZRVCjLFexlOCuWn', 'IJOtIlfsYdTyaDTRVrLI']
const swipers = PICTURE.map(item =>
({
  id: item,
  url: 'https://zos.alipayobjects.com/rmsportal/' + item + '.png',
  alt: item,
})
)
mock(domain + 'swipers', () =>
({
  code: 200,
  message: 'OK',
  data: swipers
})
)

//小组数据
const groups = mock({
  'list|4': [{
    'id|+1': 0,
    title: '@ctitle(3)',
    desc: '@csentence(5)',
    // Random.image( size, background, foreground, format, text )
    img: Random.image('60x60', '#50B347', '#FFF', 'png', '@cword')
  }]
})

mock(domain + 'groups', () =>
({
  code: 200,
  message: 'OK',
  data: groups.list
})
)

//资讯数据
const news = mock({
  'list|4': [{
    'id|+1': 0,
    title: '@csentence()',
    from: '@cname',
    date: '@date',
    // Random.image( size, background, text )
    img: Random.image('160x100', '#FF6600', '@cword')
  }]
})

mock(domain + 'news', () =>
({
  code: 200,
  message: 'OK',
  data: news.list
})
)

//城市数据
const citys = mock([
  {
    id: 0,
    label: '北京',
    date: '@date',
  },
  {
    id: 1,
    label: '上海',
    date: '@date',
  },
  {
    id: 2,
    label: '广州',
    date: '@date',
  },
  {
    id: 3,
    label: '深圳',
    date: '@date',
  },
  {
    id: 4,
    label: '西安',
    date: '@date',
  },
])

mock(domain + 'citys', options => {
  const city = citys.filter(item => options.body.indexOf(item.label)>-1)

  return {
    code: 200,
    message: 'OK',
    data: city.length !== 0? city[0]:citys[0]
  }
})
